//
//  SAPFindTableViewCell.m
//  CarsHome
//
//  Created by dapeng on 15/12/5.
//  Copyright © 2015年 dapeng. All rights reserved.
//

#import "SAPFindTableViewCell.h"
#import "Theme-PrefixHeader.pch"
@implementation SAPFindTableViewCell
- (void)dealloc {
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.backgroundColor = [[ConfigurationTheme shareInstance] getThemeColorWithName:@"ygColor"];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeColor) name:ThemeChangeNotification object:nil];
        [self changeColor];
    }return self;
}
- (void)changeColor {
    
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    for (int i = 0; i < 8; i++) {
        UIView *views = (UIView *)[self viewWithTag:100 + i];
        UIImageView *sellImage = (UIImageView *)[self viewWithTag:110 + i];
        sellImage.frame = CGRectMake(0, 0, SCREEN_SIZE.width / 2, SCREEN_SIZE.width / 2 - 70);
        UILabel *title = (UILabel *)[self viewWithTag:120 + i];
        title.frame = CGRectMake(10, SCREEN_SIZE.width / 2 - 70, SCREEN_SIZE.width / 2, 30);
        UILabel *adinfo = (UILabel *)[self viewWithTag:130 + i];
        adinfo.frame = CGRectMake(10, SCREEN_SIZE.width / 2 - 40, SCREEN_SIZE.width / 2, 20);
        UILabel *state = (UILabel *)[self viewWithTag:140 + i];
        state.frame = CGRectMake(10, SCREEN_SIZE.width / 2 - 20, SCREEN_SIZE.width / 2, 15);
       
        if (i % 2 == 0) {
            views.frame = CGRectMake(0, SCREEN_SIZE.width * i / 4, SCREEN_SIZE.width / 2, SCREEN_SIZE.width / 2 + 30);
        }else {
            views.frame = CGRectMake(SCREEN_SIZE.width / 2, SCREEN_SIZE.width * (i - 1) / 4, SCREEN_SIZE.width / 2, SCREEN_SIZE.width / 2 + 30);
        }

    }
}
- (void)setThreeModel:(SAPFindThreeModel *)threeModel {
    if (_threeModel != threeModel) {
        [_threeModel release];
        _threeModel = [threeModel retain];
    }
    for (int i = 0; i < threeModel.listArray.count; i++) {
    SAPFindTwoModel *twoModel = threeModel.listArray[i];
        UIView *views = [[UIView alloc] initWithFrame:CGRectZero];
        views.tag = 100 + i;
        
        UIImageView *sellImage = [[UIImageView alloc] initWithFrame:CGRectZero];
        [sellImage sd_setImageWithURL:[NSURL URLWithString:twoModel.logo] placeholderImage:[UIImage imageNamed:@"zhanwei.png"]];
        sellImage.tag = i + 110;

        UILabel *title = [[UILabel alloc] initWithFrame:CGRectZero];
        title.text = twoModel.title;
        title.tag = i + 120;
        
        UILabel *adinfo = [[UILabel alloc] initWithFrame:CGRectZero];
        adinfo.text = twoModel.adinfo;
        adinfo.font = [UIFont systemFontOfSize:14];
        adinfo.textColor = [UIColor redColor];
        adinfo.tag = i + 130;
        
        UILabel *state = [[UILabel alloc] initWithFrame:CGRectZero];
        state.text = twoModel.state;
        state.font = [UIFont systemFontOfSize:11];
        state.tag = i + 140;
       
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        NSString *passWord = [ user objectForKey:@"userPassWord"];
        if (!(passWord == nil) && [passWord isEqualToString:@"123456"]) {
            
        }else {
            state.textColor = RGB(153.0,153.0,153.0,1.0f);
            adinfo.textColor = RGB(153.0,153.0,153.0,1.0f);
            title.textColor = RGB(153.0,153.0,153.0,1.0f);
            
        }
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickAction:)];
        [views addGestureRecognizer:tap];
        [views addSubview:state];
        [views addSubview:adinfo];
        [views addSubview:sellImage];
        [views addSubview:title];
        [self addSubview:views];
        [sellImage release];
        [title release];
        [adinfo release];
        [state release];
        [views release];
    }
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *passWord = [user objectForKey:@"nightModel"];
    
    if (!(passWord == nil) && [passWord isEqualToString:@"day"]) {
        self.backgroundColor = [UIColor colorWithWhite:0.126 alpha:1.000];
        
    }else{
        self.backgroundColor = [UIColor whiteColor];
        
    }
   
}

- (void)clickAction:(UITapGestureRecognizer *)sender {
    _count = sender.view.tag - 100;
    [self.delegate passFindValue:_count];
    
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
